package com.linkage.linkedlife.ui.activity

import android.os.Bundle
import android.os.Handler
import android.util.Log
import androidx.databinding.DataBindingUtil
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.clark.dingding.constants.ARouterPath
import com.linkage.linkedlife.R
import com.linkage.linkedlife.base.BaseActivity
import com.linkage.linkedlife.utils.PollingUtil
import kotlinx.android.synthetic.main.activity_splash.*

/**
 * @ClassName: SplashActivity
 * @Description: java类作用描述
 * @Author: Clark
 * @Date: 2021/1/12 0012 13:57
 */

class SplashActivity : BaseActivity() {

    private lateinit var runnable: Runnable
    private var countNum = 3;
    private lateinit var mHandler: Handler
    //数据绑定的方式1 对应的layout 应该是layout 标签开头 kotlin java 都可以用

    /**绑定的方式2
    lateinit var activitySplashBinding: ActivitySplashBinding
    public override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    activitySplashBinding = DataBindingUtil.setContentView(this, R.layout.activity_splash)
    //加载git动画
    Glide.with(this).load(R.drawable.top).diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(activitySplashBinding.splashImg)
    }
     **/
    //数据绑定的方式2 通过kotlin-extensions

    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)

        //加载git动画
        Glide.with(this).load(R.drawable.top).diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(splash_img)
        mHandler = Handler()
        runnable = Runnable {
            runOnUiThread {
                if (countNum != 0) {
                    mHandler.postDelayed(runnable, 1000)
                } else {
                    //页面的跳转
                    ARouter.getInstance().build(ARouterPath.GuidanceActivity).navigation()
                }
                splash_count.text = "" + countNum
                countNum--;
                Log.d("clark", "" + countNum + (countNum == 0))
            }
        }
        mHandler.postDelayed(runnable, 1000)
    }


}